#pragma once

#ifndef FILEHELPER_H
#define FILEHELPER_H

#include <QObject>
#include <QFileInfo>
#include "singleton.h"

class FileHelper : public QObject
{
    Q_OBJECT
public:
    SINGLETON(FileHelper)
    // QML可访问属性示例
    Q_PROPERTY(QString lastError READ lastError NOTIFY errorOccurred)

    explicit FileHelper(QObject* parent = nullptr);

    // 最后错误信息
    QString lastError() const;

    // QML可调用方法
    Q_INVOKABLE bool exists(const QString& path) const;
    Q_INVOKABLE QString readText(const QString& path, const char* codecName = "UTF-8");
    Q_INVOKABLE bool writeText(const QString& path, const QString& content);
    Q_INVOKABLE bool copy(const QString& src, const QString& dest);
    Q_INVOKABLE bool remove(const QString& path);
    Q_INVOKABLE QVariantMap getInfo(const QString& path);

signals:
    void errorOccurred(const QString& message);

private:
    QString m_lastError;

    bool copyRecursive(const QString& src, const QString& dest);
    void setError(const QString& error);
};

#endif // FILEHELPER_H
